# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=lensfun
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.3.2
pkgrel=10
pkgdesc="Database of photographic lenses and a library that allows advanced access to the database (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://lensfun.github.io/"
license=("LGPL3")
makedepends=("${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-python"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-doxygen")
depends=("${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-libpng"
         "${MINGW_PACKAGE_PREFIX}-zlib")
options=('staticlibs' 'strip')
source=(${_realname}-${pkgver}.tar.gz::https://github.com/lensfun/lensfun/archive/v${pkgver}.tar.gz
        lensfun-update-data.patch
        cmake-mingw.patch
        fix-cpp11-warnings.patch)
sha256sums=('ae8bcad46614ca47f5bda65b00af4a257a9564a61725df9c74cb260da544d331'
            'bba9bfca4469febaa8576f9245e98260fdfecadf10c3a2419013a8fa8e3af84d'
            '279ac435096d3eb9577eb0b9a2a460a4bbab7487e71a6f793a02b0b947acd502'
            '0cb1386be1ba04d7a6cd7f5f128bf1e4eb03249ec0c4ad40ebe203666b157537')

prepare(){
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i "${srcdir}/cmake-mingw.patch"
  patch -p1 -i "${srcdir}/lensfun-update-data.patch"

  # https://github.com/lensfun/lensfun/commit/694542f.patch
  patch -p1 -i "${srcdir}/fix-cpp11-warnings.patch"
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir ${srcdir}/build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=;-DSETUP_PY_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"Ninja" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DSETUP_PY_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DBUILD_STATIC=OFF \
    -DBUILD_AUXFUN=ON \
    -DBUILD_LENSTOOL=ON \
    -DBUILD_TESTS=OFF \
    -DBUILD_FOR_SSE=ON \
    -DBUILD_FOR_SSE2=ON \
    -DBUILD_DOC=OFF \
    ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/cmake.exe --build ./
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake.exe --build ./ --target install
}
